function add(num1, num2) {
    return num1 + num2;
}
function sub(num1, num2) {
    return num1 - num2;
}
function multiply(num1, num2) {
    return num1 * num2;
}
/* origin version calculator: */
// function calculator(num1, num2, operator) {
//     return operator(num1, num2);
// }
/* the more robust calculator*/
function calculator(num1, num2, operator) {
    // Check inputs are number or not - Common logic
    if (isNaN(num1) || isNaN(num2)) {
        console.log("\terror:input(s) are not a number:");
        return;
    }
    return operator(num1, num2);
}
ret1 = calculator(10, 5, add);
console.log("result1:" + ret1)
ret2 = calculator(10, 5, sub);
console.log("result2:" + ret2)
ret3 = calculator(10, "NotNumberArgument", multiply);
console.log( "result3:" + ret3)